<template>
  <j-modal
    :title="title"
    :width="800"
    :visible="visible"
    :maskClosable="false"
    :ok-button-props="{ props: { disabled: disableSubmit } }"
    :fullscreen="true"
    @close="close"
    cancelText="关闭"
  >
    <div style="margin: 0 auto" :class="{ isCheck: isCheck }">
      <a-form-model ref="form" :rules="validatorRules" :model="queryParam">
        <table class="table table-striped table-bordered" align="center" valign="center">
          <tr>
            <td class="column title" colspan="12">基本信息</td>
          </tr>
          <tr>
            <td class="column">机构名称</td>
            <td class="value">
              <a-form-model-item label="" prop="name">
                <a-input :disabled="disableSubmit" v-model="queryParam.name"></a-input>
              </a-form-model-item>
            </td>
            <td class="column">法定代表人</td>
            <td class="value">
              <a-form-model-item label="" prop="legalPerson">
                <a-input :disabled="disableSubmit" v-model="queryParam.legalPerson"></a-input>
              </a-form-model-item>
            </td>
            <td class="column">机构地址</td>
            <td class="value">
              <a-input :disabled="disableSubmit" v-model="queryParam.address"></a-input>
            </td>
            <td class="column">邮政编码</td>
            <td class="value">
              <a-input :disabled="disableSubmit" v-model="queryParam.postCode"></a-input>
            </td>
          </tr>
          <tr>
            <td class="column">联系人</td>
            <td class="value">
              <a-input :disabled="disableSubmit" v-model="queryParam.contact"></a-input>
            </td>
            <td class="column">联系电话</td>
            <td class="value">
              <a-input :disabled="disableSubmit" v-model="queryParam.phone"></a-input>
            </td>
            <td class="column">电子邮箱</td>
            <td class="value">
              <a-input :disabled="disableSubmit" v-model="queryParam.email"></a-input>
            </td>
            <td class="column">传真</td>
            <td class="value">
              <a-input :disabled="disableSubmit" v-model="queryParam.fax"></a-input>
            </td>
          </tr>
          <tr>
            <td class="column">注册资本(万)</td>
            <td class="value">
              <a-input :disabled="disableSubmit" v-model="queryParam.regMoney"></a-input>
            </td>
            <td class="column">成立时间</td>
            <td class="value">
              <j-date style="width: 100%" :disabled="disableSubmit" v-model="queryParam.estabDate"></j-date>
            </td>
            <td class="column">从业人数</td>
            <td class="value">
              <a-input-number :disabled="disableSubmit" :min="0" :max="10000" class="InputNumber"
                              v-model="queryParam.numberOfEmploy"/>
            </td>
            <td class="column">主审会计师</td>
            <td class="value">
              <a-input :disabled="disableSubmit" v-model="queryParam.chiefAccountant"></a-input>
            </td>
          </tr>
          <tr>
            <td class="column">聘用方式</td>
            <td class="value">
              <a-input :disabled="disableSubmit" v-model="queryParam.hireStyle"></a-input>
            </td>
          </tr>
          <tr>
            <td class="column">审计服务项目</td>
            <td class="value" colspan="7">
              <a-textarea :disabled="disableSubmit" allow-clear
                          :auto-size="{ minRows: 3, maxRows: 3 }" v-model="queryParam.serviceItems"/>
            </td>
          </tr>
          <tr>
            <td class="column">外聘事由</td>
            <td class="value" colspan="7">
              <a-textarea :disabled="disableSubmit" allow-clear
                          :auto-size="{ minRows: 3, maxRows: 3 }" v-model="queryParam.externalCause"/>
            </td>
          </tr>
          <tr>
            <td class="column title" colspan="12">年检情况</td>
          </tr>
          <tr>
            <td class="column">企业法人营业执照</td>
            <td class="value">
              <a-input :disabled="disableSubmit" v-model="queryParam.yearcheck1"></a-input>
            </td>
            <td class="column">组织机构代码证</td>
            <td class="value">
              <a-input :disabled="disableSubmit" v-model="queryParam.yearcheck2"></a-input>
            </td>
            <td class="column">注册会计师资质证书</td>
            <td class="value">
              <a-input :disabled="disableSubmit" v-model="queryParam.yearcheck3"></a-input>
            </td>
            <td class="column">注册会计师数量</td>
            <td class="value">
              <a-input-number :disabled="disableSubmit" :min="0" :max="10000" class="InputNumber"
                              v-model="queryParam.cpanum"/>
            </td>
          </tr>
          <tr>
            <td class="column">注册税务师数量</td>
            <td class="value">
              <a-input-number :disabled="disableSubmit" :min="0" :max="10000" class="InputNumber"
                              v-model="queryParam.cetanum"/>
            </td>
          </tr>
          <tr>
            <td class="column">执业情况介绍</td>
            <td class="value" colspan="7">
              <a-textarea :disabled="disableSubmit" allow-clear
                          :auto-size="{ minRows: 3, maxRows: 3 }" v-model="queryParam.practiceIntroduction"/>
            </td>
          </tr>
          <tr>
            <td class="column">附送材料</td>
            <td class="value" colspan="7">
              <a-textarea :disabled="disableSubmit" v-model="queryParam.attachedMaterial" allow-clear
                          :auto-size="{ minRows: 3, maxRows: 3 }"/>
            </td>
          </tr>
          <tr>
            <td class="column" colspan="1">附件</td>
            <td class="value" colspan="7" style="position: relative">
              <ZUpload
                :isShow="disableSubmit"
                ref="fileUpload"
                :fileid="queryParam.fileId"
                @uploadFile="uploadFile"
              ></ZUpload>
            </td>
          </tr>
        </table>
      </a-form-model>
    </div>
  </j-modal>
</template>

<script>
  import {httpAction, getAction} from '@/api/manage'
  import ZUpload from '../../components/ZUpload'
  import store from '@/store/'

  export default {
    name: 'CheckAndEditModel',
    components: {
      ZUpload
    },
    data() {
      return {
        disableSubmit: false,
        title: '新增专家管理',
        visible: false,
        isCheck: false,
        queryParam: {},
        url: {
          get: '/sjzyzhgl/sjResourceExternalAuditInstitution/findExternalAuditPersonDetailById',
          edit: '/sjzyzhgl/sjResourceExternalAuditInstitution/edit',
          add: '/sjzyzhgl/sjResourceExternalAuditInstitution/add',
        },
        validatorRules: {
          legalPerson: [{required: true, message: '请输入!'}],
          name: [{required: true, message: '请输入!'}]
        },
      }
    },
    created() {
    },
    methods: {
      add() {
        this.model = {}
        this.queryParam = {}
        this.visible = true
      },
      check(record) {
        this.model = Object.assign({}, record)
        this.visible = true
        this.httpRequest()
      },
      edit(record) {
        this.model = Object.assign({}, record)
        this.visible = true
        this.httpRequest()
      },
      httpRequest() {
        getAction(this.url.get, {id: this.model.id}).then((res) => {
          if (res.success && res.result.length > 0) {
            this.queryParam = res.result[0]
          } else {
            console.log(res)
          }
        })
      },
      close(isSubmit) {
        if (isSubmit) {
          this.saveData()
        } else {
          this.visible = false
        }
      },
      uploadFile(id) {
        let url, type
        if (!this.model.id) {
          url = this.url.add
          type = 'post'
        } else {
          url = this.url.edit
          type = 'put'
        }
        this.queryParam.fileId = id
        this.queryParam.unit = store.getters.departInfo.id
        httpAction(url, this.queryParam, type)
          .then((res) => {
            if (res.success) {
              this.$message.success(res.message)
              this.$emit('ok')
              this.visible = false
            } else {
              console.log(res)
            }
          })
      },
      saveData() {
        this.$refs.form.validate((valid) => {
          if (valid) {
            this.$refs.fileUpload.saveFile('wbsj')
          } else {
            return false
          }
        })
      }
    }
  }
</script>

<style lang="less" scoped>
  @import '../../css/checkAndEdit.less';

  .name-type {
    width: 110px;
    margin-left: 5px;
    border: 1px solid #e0e0e0;

    /deep/ .ant-select-selection {
      box-sizing: border-box;
      min-height: 27px !important;

      .ant-select-selection__rendered {
        line-height: 27px !important;
      }
    }
  }
  .InputNumber{
    width: 100%;
    height:100%;
  }
</style>
